{% extends 'base_templates/_page_layout.html' %}
{% load web_tags %}

{% block css %}
    <style>
    </style>
    <!-- DataTables -->
    <link href="/static/plugins/minton/plugins/datatables/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css">
    <link href="/static/plugins/minton/plugins/datatables/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css">

    <!-- Responsive datatable examples -->
    <link href="/static/plugins/minton/plugins/datatables/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css">
{% endblock %}

{% block title %}

    <!-- Page-Title -->
    <div class="row">
        <div class="col-sm-12">
            <div class="page-title-box">
                <h1 class="page-title">模板管理</h1>
                <ol class="breadcrumb float-right">
                    <li class="breadcrumb-item"><a href="/resume/template/{{ obj.id }}/change">{{ obj.name }}</a></li>
                    <li class="breadcrumb-item"><a href="/resume/temolate/list">模板管理</a></li>
                    <li class="breadcrumb-item active">模板管理</li>
                </ol>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>

{% endblock %}

{% block conent %}

<div class="row">
    <div class="col-12">
        <div class="card-box">
            <h4 class="m-t-0 header-title">编辑模板</h4>
            <p class="text-muted m-b-30 font-14">
                编辑模板 <code>{{ obj.name }}</code> .
            </p>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card-box">
                        <form class="" method="post">
                            <div class="form-group ">
                                <label>Name</label>
                                {{ form_obj.name }}
                            </div>
                            <div class="form-group ">
                                <label>Url</label>
                                {{ form_obj.url }}
                            </div>
                            
                            
                            <div class="form-group col-md-12">
                                <div class="form-group mx-sm-3 text-right">
                                    <button id="" class="btn btn-primary" data-toggle="modal" data-target="#"> <span>Save</span></button>
                                </div>
                            </div>

                        </form>
                        <div class="form-group col-md-12">
                            <div class="form-group mx-sm-3 text-right">
                                <button id="btnDeleteTemplate" class="btn btn-danger"><i class="fa fa-times"></i> <span>Delete</span></button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

    </div><!-- end col -->
</div>
        
{% endblock %}

{% block js %}
        <!-- Selection table -->
        <script src="/static/plugins/minton/plugins/datatables/dataTables.select.min.js"></script>
        <script src="/static/plugins/minton/plugins/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
        <script type="text/javascript" src="/static/plugins/minton/plugins/multiselect/js/jquery.multi-select.js"></script>
        <script type="text/javascript" src="/static/plugins/minton/plugins/jquery-quicksearch/jquery.quicksearch.js"></script>
        <script src="/static/plugins/minton/plugins/select2/js/select2.min.js" type="text/javascript"></script>
        <script src="/static/plugins/minton/plugins/bootstrap-touchspin/dist/jquery.bootstrap-touchspin.min.js" type="text/javascript"></script>
        <script src="/static/plugins/minton/plugins/bootstrap-inputmask/bootstrap-inputmask.min.js" type="text/javascript"></script>

        <script src="/static/plugins/minton/plugins/moment/moment.js"></script>
        <script src="/static/plugins/minton/plugins/mjolnic-bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
        <script src="/static/plugins/minton/plugins/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
        <script src="/static/plugins/minton/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>

        <script src="/static/plugins/minton/pages/jquery.form-advanced.init.js"></script>
        <script src="/static/plugins/minton/plugins/datatables/jquery.dataTables.min.js"></script>
        <script src="/static/plugins/minton/plugins/datatables/dataTables.bootstrap4.min.js"></script>
<script>
    jQuery(document).ready(function () {

        $('.summernote').summernote({
            height: 250,                 // set editor height
            minHeight: null,             // set minimum height of editor
            maxHeight: null,             // set maximum height of editor
            focus: false                 // set focus to editable area after initializing summernote
        });
    });

    $(function(){
        bindDeleteRole();
    });
    function bindDeleteRole(){

        $("#btnDeleteTemplate").click(function(){
            var postData = {};
            var DELETEDATA = "TemplateList"
            postData[DELETEDATA] = ["{{ obj.id }}"];
            
            
            if (!jQuery.isEmptyObject(postData[DELETEDATA])){
                swal({
                    title: '你确定要删除？',
                    text: "点击确定后会进行删除！",
                    type: 'question', // warning
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    confirmButtonClass: 'btn btn-success mt-2 delete-resume-source',
                    cancelButtonClass: 'btn btn-danger ml-2 mt-2',
                    buttonsStyling: false
                }).then(function () {
                    
                }, function (dismiss) {
                    if (dismiss === 'cancel') {
                        swal({
                            title: '已取消',
                            text: "成功取消删除操作!",
                            type: 'success',
                            confirmButtonClass: 'btn btn-confirm mt-2'
                        })
                    }
                });
                $('.delete-resume-source').click(function () {
                    postData[DELETEDATA] = JSON.stringify(postData[DELETEDATA])
                    DeleteData(postData);
                })
            }else {
                $.Notification.autoHideNotify('error', 'top right', '无效的删除','无效的操作，没有需要删除的数据，请查看后再次删除!')
            }
            
        })
    }
    function DeleteData(postData){
        $.ajax({
            url: '/resume/template/delete',
            data: postData,
            type: 'POST',
            dataType: "JSON",
            success: function(arg){
                if (arg.status_code != "200"){
                    swal({
                        title: '错误',
                        text: "数据删除失败!",
                        type: 'error',
                        confirmButtonClass: 'btn btn-confirm mt-2'
                    })
                }else{
                    swal({
                        title: '已删除',
                        text: "数据删除成功!",
                        type: 'success',
                        confirmButtonClass: 'btn btn-confirm mt-2'
                    }).then(function () {
                        window.location.href="/resume/template/list";
                    });
                    
                }
            }
        })
    }
</script>
{% endblock %}